import request from '@/utils/request'
import store from '@/store'
//const ascriptionId = store.state.userInfo.ascriptionId;

// 页面内容 左侧树
export function getPage(queryParams) {
  const data = {
    ascriptionId: store.state.userInfo.ascriptionId,
    currentPage: queryParams.currentPage,
    pagesize: queryParams.pagesize
  }
  return request({
    url: '/getDepartmentPage',
    method: 'post',
    data: data
  })
}


// 数据列表
export function listData(queryParams) {
  const data = {
    ascriptionId: store.state.userInfo.ascriptionId,
    deptId: queryParams.dictId,
    currentPage: queryParams.currentPage,
    pagesize: queryParams.pagesize,
    keywords: queryParams.keywords
  }
  return request({
    url: '/getDepartmentList',
    method: 'post',
    data: data
  })
}

//  新增
export function addData(val) {
  const data = {
    projectContent: {
      ascriptionId: store.state.userInfo.ascriptionId,
      deptName: val.deptName,
      sort: val.sort,
      tid: val.tid, //顶级部门 id
      pathIds: val.pathIds, //上级部门路径
      deptId: val.deptId, //上级部门 id
      hierarchyId: val.hierarchyId, //部门层级id
      hierarchy: val.hierarchy, //部门层级
      deptCode: val.deptCode
    }
  }

  return request({
    url: '/addDepartment',
    method: 'post',
    data: data
  })
}

// 获取单条数据
export function getData(theid) {
  const data = {
    theid
  }
  return request({
    url: '/getDepartmentData',
    method: 'post',
    data: data
  })
}

// 修改
export function updateData(val) {
  const data = {
    projectContent: {
      ascriptionId: store.state.userInfo.ascriptionId,
      theid: val.theid,
      deptName: val.deptName,
      sort: val.sort,
      tid: val.tid, //顶级部门 id
      deptId: val.deptId, //上级部门 id
      hierarchyId: val.hierarchyId, //部门层级id
      hierarchy: val.hierarchy, //部门层级
      deptCode: val.deptCode
    }
  }
  // theid
  return request({
    url: '/updateDepartment',
    method: 'post',
    data: data
  })
}

// 删除
export function delData(theid) {
  const data = {
    theid
  }
  return request({
    url: '/delDepartment',
    method: 'post',
    data: data
  })
}

// 批量删除   idListStr id列表  逗号隔开
export function delMultiData(idListStr) {
  const data = {
    idListStr
  }
  return request({
    url: '/delMultipleDepartment',
    method: 'post',
    data: data
  })
}

// 状态启用
export function EnableStaff(theid, enable) {
  const data = {
    projectContent: {
      theid,
      enable
    }
  }
  return request({
    url: '/changeEnableDepartment',
    method: 'post',
    data: data
  })
}